/* 
*  Copyright (C) 2009-2010 WCG Project
*
*  This program is free software; you can redistribute it and/or modify it
*  under the terms of the GNU General Public License as published by the
*  Free Software Foundation; either version 2 of the License, or (at
*  your option) any later version.
*
*  This program is distributed in the hope that it will be useful, but
*  WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
*  General Public License for more details.
*
*  You should have received a copy of the GNU General Public License
*  along with this program; if not, write to the Free Software Foundation,
*  Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*  In addition, as a special exception, the author gives permission to
*  link the code of this program with the Half-Life Game Engine ("HL
*  Engine") and Modified Game Libraries ("MODs") developed by Valve,
*  L.L.C ("Valve"). You must obey the GNU General Public License in all
*  respects for all of the code used other than the HL Engine and MODs
*  from Valve. If you modify this file, you may extend this exception
*  to your version of the file, but you are not obligated to do so. If
*  you do not wish to do so, delete this exception statement from your
*  version.
*/




new bool:g_iUltimateIconShown[33]
new bool:g_iAbilityIconShown[33]
new bool:g_iUltIconFlashing[33]

#define ULTIMATE_ICON	"suit_full"
#define ABILITY_ICON	"cross"

/*
new g_UltimateIcons[][] = {
		"dmg_rad",				// Undead
		"item_longjump",		// Human Alliance
		"dmg_shock",			// Orcish Horde
		"item_healthkit",		// Night Elf
		"dmg_heat",				// Blood Mage
		"suit_full",			// Shadow Hunter
		"cross",				// Warden
		"dmg_gas"				// Crypt Lord
	}
*/	

// This function will handle ultimate icons - basically shows if appropriate or hides if appropriate
IconHandler( id )
{
	if( !is_user_alive(id) )
		return

	new iSkillID
	new bool:bSound = false
	new bool:bShowUltimateIcon = true
	new bool:bShowabilityIcon = true

	if( !g_iUltIconFlashing[id] )
	{
		iSkillID = PlayerInfo[id][PI_SelectedUltimate]
		if( !IsValidSkill( iSkillID ) || iSkillID == SKILL_NONE )
			bShowUltimateIcon = false
	
		else if( PlayerInfo[id][PI_SpellCooldown+(S_PLAYERINFO:iSkillID)] > 0 )
			bShowUltimateIcon = false
	
		else if( PlayerInfo[id][PI_Mana] < SM_GetManaCost( id, iSkillID ) )
			bShowUltimateIcon = false
	
	
		if( !bShowUltimateIcon && g_iUltimateIconShown[id] )
			ULT_ClearIcons( id )
	
		else if( bShowUltimateIcon && !g_iUltimateIconShown[id] )
		{
			// Play the ultimate ready sound
			client_cmd( id, "speak %s", g_szSounds[SOUND_ULTIMATEREADY] )
			bSound = true
	
			// Give the user a graphical message that their ultimate is ready
			WCG_StatusText( id, TXT_ULTIMATE, HUD_ULTIMATE, "%L", id, "ULTIMATE_READY" )
	
			// Show their ultimate icon
			ULT_Icon( id, ICON_SHOW )
		}
	}






	iSkillID = PlayerInfo[id][PI_SelectedAbility]
	if( !IsValidSkill( iSkillID ) || iSkillID == SKILL_NONE )
		bShowabilityIcon = false

	else if( PlayerInfo[id][PI_SpellCooldown+(S_PLAYERINFO:iSkillID)] > 0 )
		bShowabilityIcon = false

	else if( PlayerInfo[id][PI_Mana] < SM_GetManaCost( id, iSkillID ) )
		bShowabilityIcon = false


	if( !bShowabilityIcon && g_iAbilityIconShown[id] )
		Ability_ClearIcons( id )

	else if( bShowabilityIcon && !g_iAbilityIconShown[id] )
	{
		if( !bSound )
			client_cmd( id, "speak %s", g_szSounds[SOUND_ULTIMATEREADY] )

		// Give the user a graphical message that their ultimate is ready
		WCG_StatusText( id, TXT_ULTIMATE, HUD_ULTIMATE, "%L", id, "ABILITY_READY" )

		// Show their ultimate icon
		Ability_Icon( id, ICON_SHOW )
	}


}


// This function will display/flash/hide the race's ultimate icon on the screen
ULT_Icon( id, flag )
{
	if( !is_user_alive( id ) )
	{
		ULT_ClearIcons( id )
		return
	}

	new iSkillID = PlayerInfo[id][PI_SelectedUltimate]
	
	if( PlayerInfo[id][PI_Class] == CLASS_NONE || iSkillID == SKILL_NONE )
		return

	if( flag == ICON_FLASH )
	{
		g_iUltIconFlashing[id] = true
		Create_StatusIcon( id, flag, ULTIMATE_ICON, 128, 128, 128 )
	}
	else
	{
		g_iUltIconFlashing[id] = false
		Create_StatusIcon( id, flag, ULTIMATE_ICON, 64, 128, 0 )
	}

	// Remember what icon we displayed
	if( flag == ICON_SHOW || flag == ICON_FLASH )
		g_iUltimateIconShown[id] = true

	// No icon shown
	else if ( flag == ICON_HIDE )
		ULT_ClearIcons( id )
}




// This function will display/flash/hide the race's ultimate icon on the screen
Ability_Icon( id, flag )
{
	if( !is_user_alive( id ) )
	{
		Ability_ClearIcons( id )
		return
	}

	if( PlayerInfo[id][PI_Class] == CLASS_NONE || PlayerInfo[id][PI_SelectedAbility] == SKILL_NONE )
		return

	// Create the status icon
	Create_StatusIcon( id, flag, ABILITY_ICON, 64, 128, 0 )

	// Remember what icon we displayed
	if( flag == ICON_SHOW || flag == ICON_FLASH )
		g_iAbilityIconShown[id] = true

	// No icon shown
	else if ( flag == ICON_HIDE )
		Ability_ClearIcons( id )
}



ULT_ClearIcons( id )
{
	// Only have icons for CS/CZ
	// Remove the last icon that was shown!
	if( g_iUltimateIconShown[id] && is_user_connected(id) )
		Create_StatusIcon( id, ICON_HIDE, ULTIMATE_ICON, 0, 0, 0 )
	
	g_iUltIconFlashing[id] = false
	g_iUltimateIconShown[id] = false
}



Ability_ClearIcons( id )
{
	// Only have icons for CS/CZ
	// Remove the last icon that was shown!
	if( g_iAbilityIconShown[id] && is_user_connected(id) )
		Create_StatusIcon( id, ICON_HIDE, ABILITY_ICON, 0, 0, 0 )

	g_iAbilityIconShown[id] = false
}
